﻿@model SPagedList<Dyd.BaseService.ServiceCenter.Domain.Model.tb_error>
@{
    ViewBag.Title = "错误日志";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var list = XXF.ProjectTool.EnumHelper<XXF.BaseService.ServiceCenter.SystemRuntime.EnumLogType>.GetAllEnumsOfList2().ToList();
    list.Insert(0, new SelectListItem { Value = "0", Text = "全部" });

    var ServiceList = ViewBag.ServiceList as IList<SelectListItem>;
}
@Html.AntiForgeryToken()
<div class="main_content">
    <div class="top">
        <h3>@ViewBag.Title</h3>
    </div>
    <div class="main">
        @using (Ajax.BeginForm("ErrorIndex", "Error", null, new AjaxOptions { UpdateTargetId = "ajaxList", InsertionMode = InsertionMode.Replace }, new { id = "ajaxForm" }))
        {
            <div class="pt10">
                <label>日志类型</label>
                @Html.DropDownList("logtype", list)
                <label>服务</label>
                @Html.DropDownList("serviceid", ServiceList)
                <input type="submit" class="btn" value="搜索" accesskey="S" />
                <input id="clear" type="button" class="btn" value="清空" />
            </div>
        }
    </div>

    <div id="ajaxList" class="m10">
        @Html.Partial("_ErrorIndex", Model)
    </div>
</div>
@section Scripts{
    <script src="~/Scripts/layer/layer.js"></script>
    <link href="~/Scripts/layer/skin/layer.css" rel="stylesheet" />
}

@section footerScripts{
    @Html.SPagerScript()
    <script>

        $(function () {

            $("#ajaxList").on("click", function (event) {
                var type = $(event.target).attr("class");
                switch (type) {
                    case "deleteItem": deleteItem(event.target); break;
                }
            });

            $("body").on("click", "#clear", function (e) {
                var id = $(this).parent().parent().attr("data-id");
                var url = "/Error/ErrorClear";
                if (window.confirm("确定要清空吗？")) {
                    $.post(url, addAntiForgeryToken({ id: "" }), function (data) {
                        if (data.Flag) {
                            alert(data.Message);
                            window.location.reload();
                        }
                        else {
                            alert(data.Message);
                        }
                    }, "json");
                }
            });
        });

        //删除
        function deleteItem(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            if (confirm("确认删除")) {
                $.ajax({
                    url: "/Error/ErrorDelete",
                    type: "post",
                    data: antiToken({ id: id }),
                    dataType: "json",
                    success: function (data) {
                        if (data.Flag) {
                            alert(data.Message);
                            window.location.reload();
                        } else {
                            alert(data.Message);
                        }
                    }
                });
            }
        }
    </script>
}